package com.example.administrator.zhjt;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.zhjt.activity.BusActivity;

/**
 * Created by Administrator on 2017/5/18 0018.
 */

public class LoadingDialog extends Dialog {

    private static final int CHANGE_TITLE_WHAT = 1;
    private static final int CHNAGE_TITLE_DELAYMILLIS = 300;
    private static final int MAX_SUFFIX_NUMBER = 3;
    private static final char SUFFIX = '.';

    private ImageView img_route;
    private TextView tv_detail;
    private TextView tv_point;
    private RotateAnimation rotateAnimation;

    public LoadingDialog(@NonNull Context context) {
        super(context);
        init();
    }

    private void init(){
        setContentView(R.layout.common_dialog);
        img_route= (ImageView) findViewById(R.id.img_route);
        tv_detail= (TextView) findViewById(R.id.tv_detail);
        tv_point= (TextView) findViewById(R.id.tv_point);
        initAnim();
    }

    private void initAnim(){
        rotateAnimation=new RotateAnimation(0,360, Animation.RESTART,0.5f,Animation.RESTART,0.5f);
        rotateAnimation.setDuration(2000);
        rotateAnimation.setRepeatCount(Animation.INFINITE);
        rotateAnimation.setRepeatMode(Animation.RESTART);
        rotateAnimation.setStartTime(Animation.START_ON_FIRST_FRAME);
    }



    @Override
    public void show() {//在要用到的地方调用这个方法
        img_route.startAnimation(rotateAnimation);
        super.show();
    }


    @Override
    public void dismiss() {
        rotateAnimation.cancel();
        super.dismiss();
    }


    @Override
    public void setTitle(CharSequence title) {
        if (TextUtils.isEmpty(title)) {
            tv_detail.setText("正在加载");
        }
        else {
            tv_detail.setText(title);
        }
    }


    @Override
    public void setTitle(int titleId) {
        setTitle(getContext().getString(titleId));
    }


    public static void dismissDialog(LoadingDialog loadingDialog) {
        if (null == loadingDialog) { return; }
        loadingDialog.dismiss();
    }

}
